package com.base.redis;

import redis.clients.jedis.Jedis;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * java连接redis测试
 *
 * @author innocent
 * @date 2019/2/18 13:45
 */
public class HelloRedis {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("localhost");
        System.out.println("本地Redis是否启动：" + jedis.ping());

        //redis list实例
        jedis.lpush("list","a","b","c");
        List<String> list = jedis.lrange("list", 0, 2);
        for (String s : list) {
            System.out.println(s);
        }

        //java redis keys实例,拿到所有的key
        Set<String> keys = jedis.keys("*");
        Iterator<String> iterator = keys.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

}
